package ca.kooki.codesnippet.core;

import junit.framework.Assert;

import org.junit.Test;

public class UserTest {

  
  @Test
  public void Name()
  {
    User user = new User("abc");
    Assert.assertEquals("abc",user.getName());
  }

  @Test
  public void Constructors()
  {
    User user = new User();
    Assert.assertEquals("",user.getName());
    Assert.assertEquals(false,user.isOfficial());

    user = new User("aha");
    Assert.assertEquals("aha",user.getName());
    Assert.assertEquals(false,user.isOfficial());

    user = new User("10","gotcha");
    Assert.assertEquals("gotcha",user.getName());
    Assert.assertEquals(true,user.isOfficial());
    Assert.assertEquals("10",user.getId());

  }
  
  @Test
  public void ToString()
  {
    User user = new User("abc");
    Assert.assertEquals("abc",user.toString());
  }
  
  @Test
  public void Annonymous()
  {
    User annon = new User("-2","annonymous");
    Assert.assertEquals(annon,User.ANNONYMOUS);
  }
  
  @Test
  public void NotEqualsWrongType()
  {
    User user = new User("aha");
    Assert.assertEquals(false, user.equals(null));
    Assert.assertEquals(false, user.equals("wrong type"));
  }

  @Test
  public void NotEqualsWrongName()
  {
    User user = new User("aha");
    User compareTo = new User("notaha");
    Assert.assertEquals(false, user.equals(compareTo));
  }

  @Test
  public void EqualsSameName()
  {
    User user = new User("aha");
    User compareTo = new User("aha");
    Assert.assertEquals(true, user.equals(compareTo));
  }

  @Test
  public void EqualsSameIdDontCareAboutName()
  {
    User user = new User("aha");
    User compareTo = new User("notaha");
    
    user.setId("2");
    compareTo.setId("2");
    
    Assert.assertEquals(true, user.equals(compareTo));
  }
  
  @Test
  public void hashCodeAvailable()
  {
    User user = new User("blah");
    Assert.assertEquals("blah".hashCode(), user.hashCode());

    user = new User("10","blah2");
    Assert.assertEquals("blah2".hashCode(), user.hashCode());
    
  }
  
}
